load("@rules_rust//rust:defs.bzl", "rust_doc_test", "rust_library", "rust_test")

package(default_visibility = ["//visibility:public"])

rust_library(
    name = "test_utilities",
    testonly = True,
    srcs = glob(["src/**"]),
    crate_name = "ic_test_utilities",
    version = "0.9.0",
    deps = [
        # Keep sorted.
        "//rs/bitcoin/replica_types",
        "//rs/config",
        "//rs/crypto/sha2",
        "//rs/crypto/tree_hash",
        "//rs/cycles_account_manager",
        "//rs/interfaces",
        "//rs/interfaces/certified_stream_store",
        "//rs/interfaces/state_manager",
        "//rs/interfaces/state_manager/mocks",
        "//rs/monitoring/metrics",
        "//rs/registry/subnet_type",
        "//rs/replicated_state",
        "//rs/test_utilities/types",
        "//rs/types/types",
        "//rs/universal_canister/lib",
        "@crate_index//:hex-literal",
        "@crate_index//:lazy_static",
        "@crate_index//:nix",
        "@crate_index//:serde",
        "@crate_index//:serde_cbor",
        "@crate_index//:socket2",
        "@crate_index//:tempfile",
        "@crate_index//:wat",
    ],
)

genrule(
    name = "empty-wasm",
    outs = ["empty_wasm.wasm"],
    # This command writes the minimal legal wasm binary to a file. See also
    # EMPTY_WASM, which is the same data as a rust constant.
    cmd = "echo -ne '\\x00\\x61\\x73\\x6d\\x01\\x00\\x00\\x00' > $@",
)

rust_test(
    name = "test_utilities_test",
    crate = ":test_utilities",
    deps = [
        # Keep sorted.
        "//rs/artifact_pool",
        "//rs/test_utilities/logger",
        "@crate_index//:rusty-fork",
        "@crate_index//:wasmprinter",
    ],
)

# TODO(IC-1207): `rust_doc_test` fails with `error: Failed to load argument file: IO Error`
# see https://dash.buildfarm.dfinity.systems/invocation/1aa6195b-afe4-4ee8-99ee-1ff46270b196
rust_doc_test(
    name = "test_utilities_doc_test",
    crate = ":test_utilities",
    deps = [
        # Keep sorted.
        "@crate_index//:rusty-fork",
    ],
)
